using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration.Json;

namespace Blog.WebApi.Command.Helper
{
    public class Appsetting
    {
        public static IConfiguration _iconfiguration { get; set; }

        static string contentPath { get; set; }

        public Appsetting(string contentPath)
        {   
            string path = "appsettings.json";            

            _iconfiguration = new ConfigurationBuilder()
            .SetBasePath(contentPath)
            .Add(new JsonConfigurationSource{Path = path, Optional = false, ReloadOnChange = true})
            .Build();
        }

        public Appsetting(IConfiguration iconfiguration)
        {
            _iconfiguration = iconfiguration;
        }

        public static string app(params string[] sections)
        {
            try
            {
                if (sections.Any())
                {
                    var test = _iconfiguration[string.Join(":", sections)];
                    return test;
                }
            }
            catch(Exception ex)
            {

            }
            return "";
        }
    }
}